package com.leyou.search.controller;

import com.leyou.common.page.pageResult;
import com.leyou.search.pojo.GoodsDTO;
import com.leyou.search.pojo.SearchRequestParam;
import com.leyou.search.service.SearchService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;
import java.util.Map;

@RestController
public class SearchController {

    @Autowired
    private SearchService searchService;

    @PostMapping("/page")//请求路径 采用 page，前端发出请求的路径：/search/page 经过网关/search/***映射  page
    public ResponseEntity<pageResult<GoodsDTO>> searchGoodsListByPage(@RequestBody SearchRequestParam searchRequestParam){

     pageResult<GoodsDTO>  pageResult=searchService.searchGoodsListByPage(searchRequestParam);

     return ResponseEntity.status(HttpStatus.OK).body(pageResult);
    }

    @PostMapping("/filter")
    public ResponseEntity<Map<String,List<?>>> queryFilters(@RequestBody SearchRequestParam searchRequestParam){

        Map<String,List<?>> filterMap=searchService.queryFilters(searchRequestParam);

        return  ResponseEntity.status(HttpStatus.OK).body(filterMap);

    }

}
